Introduction to C++ and C Programming by Hans Petter Langtangen

Introduction to C++ and C Programming by Hans Petter Langtangen

Author:Hans Petter Langtangen [Langtangen, Hans Petter]
Language: eng
Format: azw3
Publisher: Ayesha Naveed
Published: 2017-11-27T05:00:00+00:00


MyVector ClassMyVector holds both the data in the vector, the length

of the vector, as well as a set of functions for operating on the vector data

MyVector objects can be sent to Fortran/C functions:

// v is MyVector

call_my_F77_function (v.getPtr(), v.size(), ...)

// array length

The MyVector class

class MyVector

{private: double* A;

int length;

void allocate (int n);

void deallocate();public: MyVector ();

MyVector (int n);

MyVector (const MyVector& w); // MyVector v(w);

~MyVector (); // clean up dynamic memory bool redim (int n); // v.redim(m); MyVector& operator= (const MyVector& w);// v = w; double operator() (int i) const; // a = v(i); double& operator() (int i); // v(i) = a;

void print (std::ostream& o) const; // v.print(cout); double inner (const MyVector& w) const; // a = v.inner(w); int size () const { return length; } // n = v.size(); double* getPtr () { return A; } // send v.getPtr() to C/F77

};

// vector entries (C-array)

// allocate memory, length=n // free memory

// MyVector v;

// MyVector v(n);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.